package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysUserService;
import com.atguigu.spzx.model.dto.system.SysUserDto;
import com.atguigu.spzx.model.entity.system.SysUser;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "用户管理")
@RestController
@RequestMapping("/admin/system/sysUser")
//@CrossOrigin(allowCredentials = "true",originPatterns = "*",allowedHeaders = "*")
public class SysUserController {

    @Autowired
    SysUserService sysUserService;


    @Operation(summary = "分页")
    @PostMapping("/findByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<SysUser>> findByPage(@PathVariable("pageNum") Integer pageNum,
                             @PathVariable("pageSize") Integer pageSize,
                             @RequestBody SysUserDto sysUserDto) {
        PageInfo<SysUser> pageInfo =  sysUserService.findByPage(pageNum,pageSize,sysUserDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "添加")
    @PostMapping("/save")
    public Result save(@RequestBody SysUser sysUser){
        sysUserService.save(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "根据ID获取数据")
    @GetMapping("/getById/{id}")
    public Result<SysUser> getById(@PathVariable Long id){
        SysUser sysUser = sysUserService.getById(id);
        return Result.build(sysUser,ResultCodeEnum.SUCCESS);
    }


    @Operation(summary = "修改")
    @PutMapping("/update")
    public Result update(@RequestBody SysUser sysUser){
        sysUserService.update(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }


    @Operation(summary = "根据ID删除数据(逻辑删除)")
    @DeleteMapping("/deleteById/{id}")
    public Result<SysUser> deleteById(@PathVariable Long id){
        sysUserService.deleteById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }













}
